<?php

$ROOT = dirname(__FILE__);
define("LIBS","$ROOT/libs");
set_include_path(get_include_path() . PATH_SEPARATOR . LIBS);
define ("ENCODEING","utf-8");
define ('TIME_ZONE','Asia/Shanghai');
define ("APP_PATH",$ROOT);

define ("DIR_TEMPLATE",$ROOT."/templates");
define ("DIR_TEMPLATE_COMPILE",$ROOT."/templates_c");
define ("DIR_TEMPLATE_CACHE",$ROOT."/cache");
define ("DIR_TEMPLATE_LIBS",$ROOT.'/include');
define ("TEMPLATE_IS_CACHED",false);

require_once('smarty-2.6.19/Smarty.class.php');
class User_Smarty extends Smarty{

	function User_Smarty()
	{
		$this->Smarty();
		$this->template_dir = DIR_TEMPLATE;
		$this->compile_dir = DIR_TEMPLATE_COMPILE;
		$this->cache_dir =DIR_TEMPLATE_CACHE;
		$this->caching = TEMPLATE_IS_CACHED;
		$this->left_delimiter = '{{';
		$this->right_delimiter = '}}';
	}

}
$GLOBALS['tpl'] = new User_Smarty();

/*
 * render html with data
 */
function render_to_response($template_file='',$context=array() )
{
	$a = false;
	$content = array();
	if($template_file == '')
	{
		return;
	}
	global $tpl;
	foreach($context as $key => $v)
	{
		if(is_array($v)){
			$content[] = render_to_response($template_file,$v);

		}else{
		$a = true;
			//$tpl->assign($key,$v);
			$content[$key] = $v;
		}
	}
	if($a)return $content;
	$tpl->assign('content',$content);

	$encoding = defined('ENCODEING') ?ENCODEING:'UTF-8';
	header("Content-Type: text/html; charset=$encoding");

	$tpl->display($template_file);
	exit;
}

/*
 * 302:redirect
 */
function redirect($url){
	header("Location: ".$url);
	exit;
}
?>